define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                    items: [],
                    store:{},
                    loading:0,
                    title:'',
                    page:1,
                    lastpage:0,
                    status:'',
                    nodata:0,
                    commission_money:''
                    
                };
            },
            el: '#pageCard',
            created: function() {
                this.fetchData();
            },
            mounted: function() {
                    // console.log("123");
                    if (this.mounted == 1) {
                        return;
                    }
                    
                    var that = this ;
                    app.pager("#pageCard",function(){
                       that.getList();
                    });
                    this.mounted = 1;

            },
            methods: {
                fetchData: function() {
                    var _this = this;
                    this.getList();
                },
                
                setStatus:function(status){
                    // var status = $(e.target).attr("data-status");

                    if (this.status === status){
                      return ;
                    }
                      // console.log(status);
                    this.status  = status;
                     
                    this.getList(1);
                   
                },  

                
                getList:function(reload){
                    var that = this;
                    if( that.loading == 1){
                        return ;
                     }
                     if(reload==1){
                       this.page=1;
                       this.items=[];
                       this.lastpage=0;
                     }
                     if(this.lastpage==1){
                      return;
                     }
                     that.loading = 1;      
                    var user_info =  app.getUserInfo();      
                    app.get("api/user_card/get", {
                      store_id : user_info.store_id,
                      page:this.page,
                      status:this.status,
                      limit:50
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      if(res.data.list.length === 0){
                        that.lastpage=1;
                      }
                      that.page++;
                      that.items=that.items.concat(res.data.list);
                     if(that.items.length === 0){
                        that.nodata=1;
                      }else{
                        that.nodata=0;
                      }
                          
                    });
                }
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
